package com.study.queue;

import java.util.concurrent.DelayQueue;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2020/6/7 0:53
 */
public class Consumer implements Runnable
{
    private DelayQueue<Message> queue;

    public Consumer(DelayQueue<Message> queue)
    {
        this.queue = queue;
    }

    @Override
    public void run()
    {
        while (true)
        {
            try
            {
                Message take = queue.take();
                System.out.println("消费消息id：" + take.getId() + " 消息体：" + take.getBody());
            } catch (InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }
}
